package cn.com.dhcc.turbo.service.exch;

import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.ftpserver.usermanager.impl.UserMetadata;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.com.dhcc.app.core.AppEnv.ParaGetTool;
import cn.com.dhcc.app.core.base.IocBean;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.handler.modulehandler.WhereCondition;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.core.util.NetUtil;
import cn.com.dhcc.app.core.util.Status;
import cn.com.dhcc.app.core.util.StrUtil;
import cn.com.dhcc.app.core.util.UUIDGenerator;
import cn.com.dhcc.app.core.util.XstreamUtil;
import cn.com.dhcc.app.pub.core.api.DataExchService;
import cn.com.dhcc.app.pub.core.consts.AppConst;
import cn.com.dhcc.app.pub.core.consts.AppConst.ExchDataType;
import cn.com.dhcc.app.pub.core.consts.AppConst.PostheadStatus;
import cn.com.dhcc.app.pub.core.consts.KernelParam;
import cn.com.dhcc.app.pub.core.listener.RmiServerInitListener.RMISERICE_NAMESPACE;
import cn.com.dhcc.turbo.dao.exch.ExchErrorLogDao;
import cn.com.dhcc.turbo.dao.registry.AdapterDao;
import cn.com.dhcc.turbo.entity.api.Exch;
import cn.com.dhcc.turbo.entity.api.LoginInfoXml;
import cn.com.dhcc.turbo.entity.api.LoginXml;
import cn.com.dhcc.turbo.entity.api.MonitorLog;
import cn.com.dhcc.turbo.entity.api.MonitorLogs;
import cn.com.dhcc.turbo.entity.api.Posthead;
import cn.com.dhcc.turbo.entity.api.RouteLog;
import cn.com.dhcc.turbo.entity.api.RouteLogEntry;
import cn.com.dhcc.turbo.entity.api.SendResp;
import cn.com.dhcc.turbo.entity.api.SysInfosXml;
import cn.com.dhcc.turbo.entity.exch.ExchErrorLog;
import cn.com.dhcc.turbo.entity.exch.SendCmData;
import cn.com.dhcc.turbo.entity.exch.SendFileData;
import cn.com.dhcc.turbo.entity.registry.AdapterBase;
import cn.com.dhcc.turbo.entity.registry.AdapterInfo;
import cn.com.dhcc.turbo.entity.registry.DataCategory;
import cn.com.dhcc.turbo.entity.registry.NodeInfo;
import cn.com.dhcc.turbo.entity.sysmgr.UserInfo;
import cn.com.dhcc.turbo.service.exch.cmdata.CmDataExchangeLifecycle;
import cn.com.dhcc.turbo.service.exch.cmdata.SendCmDataService;
import cn.com.dhcc.turbo.service.exch.filedata.FileDataExchageLifecycle;
import cn.com.dhcc.turbo.service.exch.filedata.SendFileDataService;
import cn.com.dhcc.turbo.service.registry.AdapterBaseService;
import cn.com.dhcc.turbo.service.registry.AdapterInfoService;
import cn.com.dhcc.turbo.service.sysmgr.UserMgrService;
/**
 * 数据交换监控接口
 * 
 * @日期 2014-11-24 下午2:59:32
 * @作者  高强
 */
@Service(IocBean.DATA_EXCH_SERVICEIMPL_BEAN)
//@WebService(endpointInterface = "cn.com.dhcc.app.pub.core.api.DataExchService")
public class DataExchServiceImpl implements DataExchService {
	@SuppressWarnings("deprecation")
	private Logger logger = Log.getDetachLogger(LOGTYPE.TURBO);

	@Autowired
    private AdapterBaseService adapterBaseService;

	@Autowired
    private AdapterInfoService adapterInfoService;
	@Resource
	private WebServiceContext wsc;
	@Autowired
	private SendCmDataService sendCmDataService;
	@Autowired
	private SendFileDataService sendFileDataService;
	@Autowired
	private AdapterDao adapterDao;
	@Autowired
	private ApiUserAuthService apiUserAuthService;
	
	@Autowired
	@Qualifier(IocBean.FILE_DATA_EXCHAGE_LIFECYCLE_BEAN)
	private FileDataExchageLifecycle fileDataExchageLifecycle;
	@Autowired
	@Qualifier(IocBean.CM_DATA_EXCHANGE_LIFECYCLE_BEAN)
	private CmDataExchangeLifecycle dataExchageLifecycle;
	@Autowired
	private UserMgrService userMgrService;
	@Autowired
	private ExchErrorLogDao exchErrorLogDao;
	
	@Autowired
    private WebServiceContext context;
	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String proccess(String xml){
		try {
			Exch exch=XstreamUtil.toObject(Exch.class, xml);
			String actionName=exch.getActionName();
			Class clz=this.getClass();
			Method method=clz.getDeclaredMethod(actionName);
			method.invoke(this, new Object[]{});
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		return xml;
		
	}
	
	@Override
	public String send(String posthead,String authCode,String metadata, String data) {
		return this.handelRequest(posthead, authCode,data,metadata, AppConst.ExchDataType.CM_DATA);
	}

	

	/**
	 * 非结构化数据交换
	 * @param postname 头文件文件名称  xxxxx.xml
	 * @param fromsys  发送系统
	 * @return
	 */
	public String sendFile(String postname,String authCode,String metadata,String fromAdapter,List<String> fileItems){
		SendResp sendResp=new SendResp();
		String groupId=postname.substring(0,postname.lastIndexOf(".xml"));
		
		
		if (postname==null || "".equals(postname) || fromAdapter==null || "".equals(fromAdapter) || authCode==null || "".equals(authCode) ) {
			sendResp.setGroupId(groupId);
			sendResp.setStatus(PostheadStatus.BAD_REQUEST.value());
			sendResp.setMessage("参数不能为空");
			try {
				return XstreamUtil.toXml(sendResp);
			} catch (Exception e) {
				logger.error(e);
			}
		}
		
		return fileDataExchageLifecycle.checkToDB(postname,authCode,metadata, fromAdapter,fileItems);
	}
	
	
	/**
	 * 处理请求
	 * @param reqxml
	 * @param payload
	 * @param dataType
	 * @return
	 */
	private String handelRequest(String reqxml, String authCode,String data,String metadata, ExchDataType exchDataType) {
		String msg = "";
		String respXml = "";
		SendResp sendResp=new SendResp();
		try {
			if (StrUtil.isNotBlank(reqxml)) {
				reqxml = reqxml.trim();
			}
			//参数校验
			Status status = dataExchageLifecycle.validate(reqxml, data);
			//信息校验不过，直接返回400错误
			if (!status.isSuccess()) {
				//发送响应
				String uuid = UUIDGenerator.getUUID();
				sendResp.setGroupId(uuid);
				sendResp.setStatus(PostheadStatus.BAD_REQUEST.value());
				sendResp.setMessage(status.getMsg());
				sendResp.setDate(AppConst.dtFormat.format(new Date()));
				
				ExchErrorLog exchErrorLog = new ExchErrorLog();
				exchErrorLog.setId(UUIDGenerator.getUUID());
				exchErrorLog.setType(exchDataType.value());
				exchErrorLog.setMessage(status.getMsg());
				exchErrorLog.setPosthead(reqxml);
				exchErrorLog.setPayload(data);
				exchErrorLog.setCreated(new Date());
				exchErrorLogDao.insert(exchErrorLog);
				return XstreamUtil.toXml(sendResp);
			}
			
			//数据落地
			Posthead posthead = (Posthead) status.getData();
			
			//TODO BY 高强 信息的格式化 将to的信息填写完整
			//验证授权码的有效性
			MessageContext ctx=context.getMessageContext();
			HttpServletRequest request = (HttpServletRequest) ctx
	                .get(AbstractHTTPDestination.HTTP_REQUEST);
	        String ip = NetUtil.getRemoteIp(request);
			HttpClientUserInfo webClient=new HttpClientUserInfo();
			webClient.setAdapterCode(posthead.getFrom().getAdaptorcode());
			webClient.setAuthCode(authCode);
			UserMetadata userMetadata=new UserMetadata();
			userMetadata.setInetAddress(InetAddress.getByName(ip));
			webClient.setUserMetadata(userMetadata);
			
			if (KernelParam.authValidate && !apiUserAuthService.isAdapterAuthCodeOkForHttp(webClient)) {
				msg="授权码"+authCode+"无效";
				String uuid = UUIDGenerator.getUUID();
				sendResp.setGroupId(uuid);
				sendResp.setStatus(PostheadStatus.BAD_REQUEST.value());
				sendResp.setMessage(msg);
				sendResp.setDate(AppConst.dtFormat.format(new Date()));
				ExchErrorLog exchErrorLog = new ExchErrorLog();
				exchErrorLog.setId(UUIDGenerator.getUUID());
				exchErrorLog.setType(exchDataType.value());
				exchErrorLog.setMessage(msg);
				exchErrorLog.setPosthead(reqxml);
				exchErrorLog.setPayload(data);
				exchErrorLog.setCreated(new Date());
				exchErrorLogDao.insert(exchErrorLog);
				return XstreamUtil.toXml(sendResp);
			}
			
			
			status = dataExchageLifecycle.localStore(wsc, posthead, reqxml, data, exchDataType,metadata);
			
			
			respXml = (String) status.getData();
			return respXml;
		} catch (Exception e) {
			msg = "解析异常：" + e.fillInStackTrace();
			String uuid = UUIDGenerator.getUUID();
			sendResp.setGroupId(uuid);
			sendResp.setStatus(PostheadStatus.BAD_REQUEST.value());
			sendResp.setMessage(msg);
			sendResp.setDate(AppConst.dtFormat.format(new Date()));
			logger.error(msg, e);
			//this is Not suppose to be happend...
			try {
				respXml = XstreamUtil.toXml(sendResp);
			} catch (Exception e1) {
				logger.error(msg, e1);
			}
			//错误日志记录
			ExchErrorLog exchErrorLog = new ExchErrorLog();
			exchErrorLog.setId(UUIDGenerator.getUUID());
			exchErrorLog.setType(exchDataType.value());
			exchErrorLog.setMessage(msg);
			exchErrorLog.setPosthead(reqxml);
			exchErrorLog.setPayload(data);
			exchErrorLog.setErrstack("" + e.fillInStackTrace());
			exchErrorLog.setCreated(new Date());
			try {
				exchErrorLogDao.insert(exchErrorLog);
			} catch (DaoException e2) {
				//ignored...
			}
			return respXml;
		}
	}



	/* 通过节点编码获取交换关系节点列表
	 * (non-Javadoc)
	 * @see cn.com.dhcc.turbo.service.registry.AdapterService#getNodeList(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public String getRelNodeList(String nodeCode)
			throws ServiceException {
		String msg = "";
		String nodeInfoXML;
		List<NodeInfo> nodeInfoList = new ArrayList<NodeInfo>();
		try {
			String nodeId = adapterDao.getNodeId(nodeCode);
			nodeInfoList = adapterDao.getNodeList(nodeId);
			nodeInfoXML = XstreamUtil.toShortXml(nodeInfoList,new Class[]{NodeInfo.class});
		} catch (Exception e) {
			msg = "500服务器异常:通过节点编码获取交换关系节点列表失败";
			logger.error(msg, e);
			throw new ServiceException(msg);
		}
		return nodeInfoXML;
	}

	
	
/**
 * 验证适配器是否绑定了webservice地址
 * @param nodeCode 节点编码
 * @param adapterCode 适配器编码
 * @return
 * @throws ServiceException
 */
	public boolean adapterIsBind(String nodeCode,String adapterCode) throws ServiceException{
		WhereCondition condition=new WhereCondition();
		condition.where().eq("NODE_CODE",nodeCode).and().eq("ADAPTER_CODE", adapterCode).and().isNotNull("WSDL_URL");
		List<AdapterInfo> adapterInfoList=adapterInfoService.list(condition);
		if (adapterInfoList!=null && !adapterInfoList.isEmpty()) {
			return true;
		}
		return false;
	}
	
	
	/**
	 * 
	 * @param domainCode 业务域编码
	 * @return
	 */
	public String getSysInfoList(String domainCode) {
		SysInfosXml xml=new SysInfosXml();
	//	try {
			//List<SysInfoXml> list=sysInfoService.listByDomainCode(domainCode);
			xml.setStatus("1");
			xml.setMsg("请求成功");
			//xml.setSysInfoXmlList(list);
		/*} catch (ServiceException e) {
			xml.setStatus("0");
			xml.setMsg("服务端异常:"+e.getMessage());
		}*/
		
		try {
			return XstreamUtil.toXml(xml);
		} catch (Exception e) {
			logger.error(e);
		}
		return null;
	}
	
	/**
	 * 登陆验证接口
	 * @param adapterCode 适配器编码
	 * @param userName 用户名
	 * @param userPassword 密码
	 * @return 用户登陆信息
	 * 返回值XML字符串
	 * <login>
	 *     <status></status>状态码 0.请求错误 1.登陆失败 2.登陆成功
	 *     <msg></msg>信息提示
	 *     <loginInfo>  用户信息
	 *        <sysCode></sysCode> 系统编码
	 *        <sysName></sysName> 系统名称
	 *     </loginInfo>
	 * </login>
	 * 
	 * 
	 */
	public String login(String authCode,String userName,String userPassword){
		LoginXml login=new LoginXml();
		
		
		try {
			
			
			//授权码验证
			//验证授权码的有效性
			MessageContext ctx=context.getMessageContext();
			HttpServletRequest request = (HttpServletRequest) ctx
	                .get(AbstractHTTPDestination.HTTP_REQUEST);
	        String ip = NetUtil.getRemoteIp(request);
	        HttpClientUserInfo webClient=new HttpClientUserInfo();
			webClient.setAdapterCode(userName);
			webClient.setAuthCode(authCode);
			UserMetadata userMetadata=new UserMetadata();
			userMetadata.setInetAddress(InetAddress.getByName(ip));
			webClient.setUserMetadata(userMetadata);
			
			if (!apiUserAuthService.isAdapterAuthCodeOkForHttp(webClient)) {
				login.setStatus("1");
				login.setMsg("授权码"+authCode+"无效");
				return XstreamUtil.toXml(login);
			}
			
			//适配器详细信息
			WhereCondition condition=new WhereCondition();
			condition.where().eq("ADAPTER_CODE", userName).and().eq("ISLOCAL", "1");
			List<AdapterInfo> list=adapterInfoService.list(condition);
			AdapterInfo adapterInfo=null;
			if (list!=null && !list.isEmpty()) {
				adapterInfo=list.get(0);//
			}
			//适配器基础信息验证
			AdapterBase adapterBase=adapterBaseService.getByUniqueProperty("ADAPTER_CODE", userName);
			if (adapterBase==null || !adapterBase.getStatus().equals("0") || !adapterInfo.getAuthCode().equals(authCode) || adapterInfo.getWsdlUrl().equals("")) {
				login.setStatus("1");
				login.setMsg("适配器"+userName+"不存在或者未启用");
				return XstreamUtil.toXml(login);
			}

			
			UserInfo userInfo = userMgrService.getUserInfoByUserName(userName);
			if (userInfo != null) {
				if (!userInfo.getPwd().equalsIgnoreCase(userPassword)) {
					login.setStatus("1");
					login.setMsg("用户密码不正确");
				}else{
					LoginInfoXml loginInfoXml=new LoginInfoXml();
					loginInfoXml.setAdapterCode(userInfo.getUserName());
					loginInfoXml.setAdapterName(userInfo.getUserNameStr());
					login.setStatus("2");
					login.setMsg("登陆成功");
					login.setLoginInfo(loginInfoXml);
				}
			}else{
				login.setStatus("1");
				login.setMsg("用户"+userName+"不存在");
			}
			
			
		}  catch (Exception e) {
			login.setStatus("0");
			login.setMsg("请求异常:"+e.getMessage());
		}
		try {
			return XstreamUtil.toXml(login);
		} catch (Exception e) {
			logger.error(e);
		}
		return null;
	}
	@Override
	public String orderStatusSearch(String groupId,String orderId,String type){
		MonitorLogs monitorLogs=new MonitorLogs();
		logger.info("请求参数  groupId:"+groupId+",orderId:"+orderId+",type:"+type);
		try {
			WhereCondition condition=new WhereCondition();
			condition.where().eq("1", "1");
			
			if (type!=null && !"".equals(type)) {
				if (type.equals(AppConst.ExchDataType.FILE_DATA.value())) {
					if (StrUtil.isNotBlank(orderId)) {
						condition.and().eq("order_id", orderId);
					}
					if (StrUtil.isNotBlank(groupId)) {
						condition.and().eq("group_id", groupId);
					}
					List<SendFileData> list=sendFileDataService.list(condition);
					monitorLogs=formattToFileLog(list);
				} else {
					if (StrUtil.isNotBlank(orderId)) {
						condition.and().eq("id", orderId);
					}
					if (StrUtil.isNotBlank(groupId)) {
						condition.and().eq("pid", groupId);
					}
					condition.and().eq("DATA_TYPE", type);
					List<SendCmData> list=sendCmDataService.list(condition);
					monitorLogs=formattToCmLog(list);
				}
			}
			logger.info(XstreamUtil.toXml(monitorLogs));
			return XstreamUtil.toXml(monitorLogs);
			
		} catch (Exception e) {
			logger.error("程序出错:"+e);
		}
		
		return null;
	}
	
	
	private MonitorLogs formattToFileLog(List<SendFileData> list) throws Exception{
		MonitorLogs monitorLogs=new MonitorLogs();
		monitorLogs.setStatus("1");
		monitorLogs.setMessage("请求成功");
		List<MonitorLog> logs=new ArrayList<MonitorLog>();
		if (list!=null && !list.isEmpty()) {
			for (SendFileData sendFileData : list) {
				MonitorLog monitorLog=new MonitorLog();
				monitorLog.setId(sendFileData.getOrderId());
				monitorLog.setGroupId(sendFileData.getGroupId());
				RouteLog routeLog = XstreamUtil.toObject(RouteLog.class,sendFileData.getRoutelog());
				List<RouteLogEntry> log=new ArrayList<RouteLogEntry>();
				//同网段,不夸节点
				if (sendFileData.getCrossNode().equals(AppConst.NO) && sendFileData.getCrossNet().equals(AppConst.CrossNetType.SAME_NETWORK.value())) {
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					log.add(proccess(routeLog.getLocalSys(),"通知本地系统"));//通知本地系统
				}else if(sendFileData.getCrossNode().equals(AppConst.YES) && sendFileData.getCrossNet().equals(AppConst.CrossNetType.SAME_NETWORK.value())){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
					log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					log.add(proccess(routeLog.getLocalSys(),"通知本地系统"));//通知本地系统
				}else if(sendFileData.getCrossNet().equals(AppConst.CrossNetType.OUT_INNER_NETWORK.value()) && !sendFileData.getThroughGap().equals("2")){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					log.add(proccess(routeLog.getOuterEntrepotStore(),"网闸节点存储"));//网闸节点存储
					log.add(proccess(routeLog.getOuterGAP(),"发送到网闸"));//发送到网闸
				/*	log.add(proccess(routeLog.getInnerGAP(),"内网网闸节点下载"));//内网网闸节点下载
					log.add(proccess(routeLog.getInnerEntrepotStore(),"内网网闸节点存储"));//内网网闸节点存储
					log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
					log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
*/				}else if(sendFileData.getCrossNet().equals(AppConst.CrossNetType.OUT_INNER_NETWORK.value()) && sendFileData.getThroughGap().equals("2")){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					log.add(proccess(routeLog.getOuterEntrepotStore(),"网闸节点存储"));//网闸节点存储
					log.add(proccess(routeLog.getWaitCarvedDiscs(),"等待刻盘"));//等待刻盘
					log.add(proccess(routeLog.getCarvedDiscs(),"刻盘"));//刻盘
					/*log.add(proccess(routeLog.getAnalyzeStore(),"解析存储"));//解析存储
					if (sendFileData.getRecvNodecode().equals(sendFileData.getInnerGapNodeCode())) {//上传节点即为接收节点
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}else{
						log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}*/
				
				}else if(sendFileData.getCrossNet().equals(AppConst.CrossNetType.INNER_OUT_NETWORK.value())){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					log.add(proccess(routeLog.getWaitCarvedDiscs(),"等待刻盘"));//等待刻盘
					log.add(proccess(routeLog.getCarvedDiscs(),"刻盘"));//刻盘
					/*log.add(proccess(routeLog.getAnalyzeStore(),"解析存储"));//解析存储
					if (sendFileData.getOutGapNodeCode() != null && sendFileData.getRecvNodecode().equals(sendFileData.getOutGapNodeCode())) {//上传节点即为接收节点
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}else{
						log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}*/
				}
				monitorLog.setMonitorLog(log);
				logs.add(monitorLog);
			}
		}
		monitorLogs.setMonitorLogList(logs);
		return monitorLogs;
	}
	
	public RouteLogEntry proccess(RouteLogEntry routelog,String location){
		RouteLogEntry log=new RouteLogEntry();
		if (routelog==null) {
			log.setStatus("");
			log.setMessage("");
			log.setLocation(location);
			log.setDate(null);
		}else{
			routelog.setLocation(location);
			log=routelog;
		}
		return log;
	}
	
	private MonitorLogs formattToCmLog(List<SendCmData> list) throws Exception{
		MonitorLogs monitorLogs=new MonitorLogs();
		monitorLogs.setStatus("1");
		monitorLogs.setMessage("请求成功");
		List<MonitorLog> logs=new ArrayList<MonitorLog>();
		if (list!=null && !list.isEmpty()) {
			for (SendCmData sendCmData : list) {
				MonitorLog monitorLog=new MonitorLog();
				monitorLog.setId(sendCmData.getId());
				monitorLog.setGroupId(sendCmData.getPid());
				RouteLog routeLog =  XstreamUtil.toObject(RouteLog.class,sendCmData.getRoutelog());
				List<RouteLogEntry> log=new ArrayList<RouteLogEntry>();
				//同网段,不夸节点
				if (sendCmData.getCrossNode().equals(AppConst.NO) && sendCmData.getCrossNet().equals(AppConst.CrossNetType.SAME_NETWORK.value())) {
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					log.add(proccess(routeLog.getLocalSys(),"通知本地系统"));//通知本地系统
				}else if(sendCmData.getCrossNode().equals(AppConst.YES) && sendCmData.getCrossNet().equals(AppConst.CrossNetType.SAME_NETWORK.value())){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					if (routeLog.getRemoteStore()!=null) {
						log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
					}else{
						//找出错误的路由
						if("0".equals(routeLog.getLocalPipeline().getStatus())){
							log.add(proccess(routeLog.getLocalPipeline(),"远程存储"));//远程存储
						}else if("0".equals(routeLog.getRemotePipeline().getStatus())){
							log.add(proccess(routeLog.getRemotePipeline(),"远程存储"));//远程存储
						}else{
							log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
						}
					}
					log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					log.add(proccess(routeLog.getLocalSys(),"通知本地系统"));//通知本地系统
				}else if(sendCmData.getCrossNet().equals(AppConst.CrossNetType.OUT_INNER_NETWORK.value()) && !sendCmData.getThroughGap().equals("2")){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					
					if (routeLog.getOuterEntrepotStore()!=null) {
						log.add(proccess(routeLog.getOuterEntrepotStore(),"网闸节点存储"));//网闸节点存储
					}else{
						//找出错误的路由
						if("0".equals(routeLog.getSendDataToOuterSendPipeline().getStatus())){
							log.add(proccess(routeLog.getSendDataToOuterSendPipeline(),"网闸节点存储"));//网闸节点存储
						}else if("0".equals(routeLog.getOuterRecvPipeline().getStatus())){
							log.add(proccess(routeLog.getOuterRecvPipeline(),"网闸节点存储"));//网闸节点存储
						}else{
							log.add(proccess(routeLog.getOuterEntrepotStore(),"网闸节点存储"));//网闸节点存储
						}
					}
					
					log.add(proccess(routeLog.getOuterGAP(),"发送到网闸"));//发送到网闸
					/*log.add(proccess(routeLog.getInnerGAP(),"内网网闸节点下载"));//内网网闸节点下载
					log.add(proccess(routeLog.getInnerEntrepotStore(),"内网网闸节点存储"));//内网网闸节点存储
					log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
					log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
*/				}else if(sendCmData.getCrossNet().equals(AppConst.CrossNetType.OUT_INNER_NETWORK.value()) && sendCmData.getThroughGap().equals("2")){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					
					if (routeLog.getOuterEntrepotStore()!=null) {
						log.add(proccess(routeLog.getOuterEntrepotStore(),"网闸节点存储"));//网闸节点存储
					}else{
						//找出错误的路由
						if("0".equals(routeLog.getSendDataToOuterSendPipeline().getStatus())){
							log.add(proccess(routeLog.getSendDataToOuterSendPipeline(),"网闸节点存储"));//网闸节点存储
						}else if("0".equals(routeLog.getOuterRecvPipeline().getStatus())){
							log.add(proccess(routeLog.getOuterRecvPipeline(),"网闸节点存储"));//网闸节点存储
						}else{
							log.add(proccess(routeLog.getOuterEntrepotStore(),"网闸节点存储"));//网闸节点存储
						}
					}
					
					log.add(proccess(routeLog.getWaitCarvedDiscs(),"等待刻盘"));//等待刻盘
					log.add(proccess(routeLog.getCarvedDiscs(),"刻盘"));//刻盘
					/*log.add(proccess(routeLog.getAnalyzeStore(),"解析存储"));//解析存储
					if (sendCmData.getRecvNodecode().equals(sendCmData.getInnerGapNodeCode())) {//上传节点即为接收节点
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}else{
						log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}*/
				
				}else if(sendCmData.getCrossNet().equals(AppConst.CrossNetType.INNER_OUT_NETWORK.value())){
					log.add(proccess(routeLog.getLocalStore(),"本地存储"));//本地存储
					log.add(proccess(routeLog.getWaitCarvedDiscs(),"等待刻盘"));//等待刻盘
					log.add(proccess(routeLog.getCarvedDiscs(),"刻盘"));//刻盘
					/*log.add(proccess(routeLog.getAnalyzeStore(),"解析存储"));//解析存储
					if (sendCmData.getRecvNodecode().equals(sendCmData.getOutGapNodeCode())) {//上传节点即为接收节点
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}else{
						log.add(proccess(routeLog.getRemoteStore(),"远程存储"));//远程存储
						log.add(proccess(routeLog.getRemoteSys(),"远程系统"));//远程系统
					}*/
				}
				monitorLog.setMonitorLog(log);
				logs.add(monitorLog);
			}
			
		}
		monitorLogs.setMonitorLogList(logs);
		return monitorLogs;
	}

	public String getNodeInfoList(String pcode) throws ServiceException {
		String msg = "";
		String nodeInfoXML = new String();
		List<NodeInfo> nodeInfoList = new ArrayList<NodeInfo>();
				
		try {
			NodeInfo nodeInfo = adapterDao.getLocalNode();
			nodeInfoList = adapterDao.getNodeListByPcode(nodeInfo.getId(),nodeInfo.getNetType(),pcode);
			nodeInfoXML = XstreamUtil.toShortXml(nodeInfoList, new Class<?>[]{NodeInfo.class});
		} catch (Exception e) {
			logger.error(msg, e);
			throw new ServiceException(msg);
		}
		return nodeInfoXML;
	}
	
	public String getAdapterInfoList() throws ServiceException {
		String msg = "";
		String adapterInfoXML = new String();
		List<AdapterInfo> adapterInfoList = new ArrayList<AdapterInfo>();
		
		try {
			adapterInfoList = adapterDao.getAdapterInfoList();
			/*for (AdapterInfo adapterInfo : adapterInfoList) {
				if(adapterInfo.getSysIds() == null) continue;
				String[] sysIds = adapterInfo.getSysIds().split(",");
				String sysCodes = "";
				for (String string : sysIds) {
					if(adapterDao.getSysCodeBySysId(string) != null){
						sysCodes = sysCodes + adapterDao.getSysCodeBySysId(string) + ",";
					}
				}
				adapterInfo.setSysCodes(sysCodes);
			}*/
			adapterInfoXML = XstreamUtil.toShortXml(adapterInfoList, new Class<?>[]{AdapterInfo.class});
		} catch (Exception e) {
			logger.error(msg, e);
			throw new ServiceException(msg);
		}
		return adapterInfoXML;
	}
	
	public String getDataCategoryList() throws ServiceException {
		String msg = "";
		String dataCategoryXML = new String();
		List<DataCategory> dataCategoryList = new ArrayList<DataCategory>();
		
		try {
			dataCategoryList = adapterDao.getDataCategoryList();
			dataCategoryXML = XstreamUtil.toShortXml(dataCategoryList, new Class<?>[]{DataCategory.class});
		} catch (Exception e) {
			logger.error(msg, e);
			throw new ServiceException(msg);
		}
		return dataCategoryXML;
	}
	
	public String getSystemList() throws ServiceException {
//		String msg = "";
		String sysInfoXML = new String();
		/*List<SysInfo> sysInfoList = new ArrayList<SysInfo>();
		
		try {
			sysInfoList = adapterDao.getSystemList();
			sysInfoXML = XstreamUtil.toShortXml(sysInfoList, new Class<?>[]{SysInfo.class});
		} catch (Exception e) {
			logger.error(msg, e);
			throw new ServiceException(msg);
		}*/
		return sysInfoXML;
	}



	@Override
	public String getFtpInfo(String adapterCode, String authCode) {
		String ftpIp = AppConst.mappingIp;
		Integer ftpPort = AppConst.EMBFTP.EMBFTP_PORT;
		boolean useSsl = KernelParam.encryptFtpUsessl;
		return ftpIp+"|"+ftpPort+"|"+useSsl;
	}


	public String getRmiInfo(){
		return "rmi://"+AppConst.mappingIp+":"+ParaGetTool.getPara(Integer.class, "app.rmi.port", 9160)+"/"+RMISERICE_NAMESPACE.SYNCSERVER.name();
	}

	public String getFtpInfo(){
		//需要的是映射IP
		return AppConst.mappingIp+"|"+AppConst.EMBFTP.EMBFTP_PORT;
	}
}
